import config from './config'
export default function(url,data={},method="GET"){
    return new Promise((resolve, reject)=> {
        wx.request({
            url:config.host+url,
            data,
            method,
            header:{
                cookie:wx.getStorageSync("cookies") ? wx.getStorageSync("cookies").find(item=>item.indexOf("MUSIC_U=") !== -1) : "[]"
            },
            success:(res)=>{
                // 请求成功后将cookies进行存储
                if(data.isLogin){
                    wx.setStorageSync("cookies",res.cookies);
                }
                resolve(res.data)
            },
            fail:(error)=>{
                reject(error)
            }
        })
    })
}
